package com.linwen.excise.od;

import java.util.Scanner;

/**
 * @author wlw
 * @date 2023/3/16 12:54 AM
 * 顺时针打印矩阵
 *
 */
public class Test2 {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int m = scanner.nextInt();
        int n = scanner.nextInt();
        int[][] mar = new int[m][n];
        int count = 1;
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < n; j++) {
                mar[i][j] = count++;
            }
        }

        int top = 0;
        int left = 0;
        int bottom = m-1;
        int right = n-1;
        while (top<=bottom&&left<=right){
            for (int i = top; i <= right; i++) {System.out.print(mar[top][i]+" ");}
            for (int i = top+1; i <= bottom; i++) {System.out.print(mar[i][right]+" ");}
            for (int i = right-1; i >= left; i--) {System.out.print(mar[bottom][i]+" ");}
            for (int i = bottom-1; i > top; i--) {System.out.print(mar[i][left]+" ");}
            top++;
            bottom--;
            left++;
            right--;
        }
    }
}
